package com.ajx.todo;

import android.support.v4.app.Fragment;

import com.ajx.todo.example.ExampleFragment;
import com.ajx.todo.play.PlayFragment;
import com.ajx.todo.project.ProjectFragment;
import com.ajx.todo.study.StudyFragment;
import com.ajx.todo.uiexplorer.UIExplorerFragment;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lai on 2017/9/9.
 */

public class FragmentFactory {

    private static Map<Integer, Fragment> mFragments = new HashMap<Integer, Fragment>();

    public static Fragment createFragment(int position) {
        Fragment fragment = null;
        fragment = mFragments.get(position);  //在集合中取出来Fragment
        if (fragment == null)   //如果在集合中没有取出来，需要重新创建
        {
            if (position == 0) {
                fragment = new ExampleFragment();
            } else if (position == 1) {
               fragment = new UIExplorerFragment();
            } else if (position == 2) {
                fragment = new StudyFragment();
            } else if (position == 3) {
                fragment = new PlayFragment();
            } else if (position == 4) {
                fragment = new ProjectFragment();
            } else if (position == 6) {
                //fragment = new TopFragment();
            }
            if (fragment != null) {
                mFragments.put(position, fragment);
            }
        }
        return fragment;
    }
}
